<template>
  <section class="webview fixHeight">
    <el-scrollbar style="height:100%">
      <el-form ref="form" :model="detail" label-width="100px" class="form">
        <el-form-item label="楼盘名称">
          <el-input v-model="detail.name" />
        </el-form-item>
       <!-- <el-form-item label="房屋标签">
          <el-select v-model="detail.tagsType" multiple placeholder="请选择">
            <el-option
              v-for="item in tagsTypeOptions"
              :key="item.id"
              :label="item.title"
              :value="item.simplify"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item label="类型">
          <el-input v-model="detail.floorCondition" />
        </el-form-item>
        <el-form-item label="销售地址">
          <el-input v-model="detail.salesAddress" />
        </el-form-item>
        <el-form-item label="参考单价">
          <el-input v-model="detail.unitPrice" />
        </el-form-item>
		  <el-form-item label="地址">
          <el-input v-model="detail.address" />
        </el-form-item>
        <el-form-item label="所有权年限">
          <el-input v-model="detail.ownershipNianx" />
        </el-form-item>
        <el-form-item label="经纪人">
          <el-input v-model="detail.agentName" />
        </el-form-item>
        <el-form-item>
          <el-button @click="cancel">返回</el-button>
        </el-form-item>
      </el-form>
    </el-scrollbar>
  </section>
</template>
<script>
  import { apartmentList, residentialList, typeListSon, sellAdd, sellUpdate, sellDetail } from '@/api/api'
  export default {
    data() {
      return {
        tagsTypeOptions: [],
        apartmentTypeOptions: [],
        ownershipTypeOptions: [],
        houseTypeOptions: [],
        residentialIdOptions: [],
        apartmentIdOptions: [],
        newOrSecondOptions: [
          {
            value: 1,
            label: '新房'
          },
          {
            value: 2,
            label: '二手房'
          }
        ],
        renovationTypeOptions: [],
        postIdOptions: [
          {
            value: 1,
            label: 'APP端'
          },
          {
            value: 2,
            label: 'PC端'
          }],
        detail: {
          'agentId': '',
          'apartmentId': '',
          'apartmentType': '',
          'area': 0,
          'buildingNum': '',
          'buildingType': '',
          'buildingYear': '',
          'commissionRate': 0,
          'corePoint': '',
          'developersId': '',
          'floor': 0,
          'hopePrice': 0,
          'houseOrientation': '',
          'houseSupporting': '',
          'houseType': '',
          'housingAgeType': '',
          'housingDescription': '',
          'housingDetails': '',
          'inArea': 0,
          'isElevator': true,
          'isVerify': true,
          'minPrice': 0,
          'newOrSecond': '',
          'onlyHouse': true,
          'openDate': '2020-02-12T01:47:09.516Z',
          'ownerMentality': '',
          'ownershipType': '',
          'propertyType': '',
          'propertyYears': 0,
          'regionId': '',
          'renovationType': '',
          'residentialId': '',
          'resourcesList': [
            {}
          ],
          'serviceIntroduction': '',
          'serviceType': '',
          'subsidiaryInformation': '',
          'tagsType': '',
          'title': '',
          'totalFoor': 0,
          'unitPrice': 0,
          'videoPath': '',
          'vrPath': ''
        }
      }
    },
    created() {
      if (this.$route.query.item) {
          this.detail = JSON.parse(this.$route.query.item)
          // this.detail.tagsType = this.detail.tagsType.split(',')
       
      }
      this.getMb()
    },
    methods: {
      getMb() {
        // 户型列表
        apartmentList({
          curPage: 1,
          pageSize: 999,
          name: ''
        }).then(data => {
          this.apartmentIdOptions = data.data.records
        })
        // 户型类型
        typeListSon('5268de1ed6df5ea239b7e0be7e15bacd').then(({ data }) => {
          this.apartmentTypeOptions = data
        })
        // 装修类型
        typeListSon('d284274dcf28591f7e2eb0d4c96b0ba2').then(({ data }) => {
          this.renovationTypeOptions = data
        })
        // 标签
        typeListSon('ca12c7c1bdc9c80f5dab1c48b9f21b84').then(({ data }) => {
          this.tagsTypeOptions = data
        })
        // 权属
        typeListSon('b6699e320a174f88071fe5f81f93b886').then(({ data }) => {
          this.ownershipTypeOptions = data
        })
        // 房屋类型
        typeListSon('912692f9210fc09727992bc5fea18521').then(({ data }) => {
          this.houseTypeOptions = data
        })
        // 小区列表
        residentialList({
          curPage: 1,
          pageSize: 999,
          name: ''
        }).then(data => {
          this.residentialIdOptions = data.data.records
        })
      },
      handleRemove(index) {
        this.fileList.splice(index, 1)
      },
      // 上传图片之前的验证
      handleUpload() {
      },
      // 上传成功之后的回调
      handleSuccess(res) {
        if (res.code === 200) {
          this.fileList.push(res.data)
          this.detail.logo = this.fileList[0]
        }
      },
      // 添加/编辑
      submit() {
        // 验证不通过则不提交
        if (!this.vertify()) {
          return false
        }
        const param = JSON.parse(JSON.stringify(this.detail))
        param.tagsType = param.tagsType.join(',')
        if (this.$route.query.id) {
          // 编辑
          sellUpdate(param).then(data => {
            Is.tip('编辑成功', 2000, 'success')
            this.$router.back()
          })
        } else {
          // 新增
          sellAdd(param).then(data => {
            Is.tip('添加成功', 2000, 'success')
            this.$router.back()
          })
        }
      },
      // 返回
      cancel() {
        this.$router.back()
      },
      vertify() {
        // if (Is.empty(this.detail.title)) {
        //   Is.tip('请输入标题')
        //   return false
        // }
        return true
      }
    }}
</script>
